package com.example.demo.service.impl;

import com.example.demo.mapper.WorkerOrderMapper;
import com.example.demo.pojo.GrWorkerOrder;
import com.example.demo.pojo.Worker;
import com.example.demo.service.WorkerOrdeshowService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class WorkerOrderImpal implements WorkerOrdeshowService {
    @Resource
    WorkerOrderMapper workerOrderMapper;
    @Override
    public List<GrWorkerOrder> WorkerOrderMappershow(String grName, String buBusinessname, String stateName,String seq,String buseq) {
        List<GrWorkerOrder> orders=workerOrderMapper.WorkerOrderMappershow(grName,buBusinessname,stateName,Integer.parseInt(seq),Integer.parseInt(buseq));
        return orders;
    }

    @Override
    public PageInfo<GrWorkerOrder> pageinfo(Integer page, Integer size, String grName, String buBusinessname, String stateName,String seq,String buseq) {
        int stateid=-1;
        PageHelper.startPage(page,size);
        if(seq.equals("")){
            stateid=-1;
        }else{
            stateid=Integer.parseInt(seq);
        }
        List<GrWorkerOrder> orders=workerOrderMapper.WorkerOrderMappershow(grName,buBusinessname,stateName,stateid,Integer.parseInt(buseq));
        PageInfo<GrWorkerOrder> grWorkerOrderPageInfo =new PageInfo<>(orders);
        return grWorkerOrderPageInfo;
    }

    @Override
    public PageInfo<Worker> workerinfo(int page, int size, int seq, String name, String statename) {
        String add="";
        PageHelper.startPage(page,size);
        List<Worker> workers=workerOrderMapper.c_workerselect(seq,name,statename);
        for(int i=0;i<workers.size();i++){
           String a= String.valueOf(workers.get(i).getGrSeq());
           int num =a.length();
           if(num<9){
               int q=9-num;
               for(int j=1;j<=q;j++){
                   add=add+"0";
               }
               workers.get(i).setCount(workers.get(i).getGrCount()+add+String.valueOf(workers.get(i).getGrSeq()));
           }
        }
        PageInfo<Worker> workerPageInfo =new PageInfo<>(workers);
        return workerPageInfo;
    }

    @Override
    public String workerupdete(String state, String seq) {
        int a= workerOrderMapper.workerupdete(Integer.parseInt(state),Integer.parseInt(seq));
        return "sucess";
    }

    @Override
    public String c_workerdel(int seq) {
        int a=workerOrderMapper.c_workerdel(seq);
        return "sucess";
    }


}
